'use strict';

//import $ from 'jquery';

import reqwest from 'reqwest';   //ajax请求, 支持xmlHttpRequest, JSONP, CORS, and CommonJS Promises A.

const fetchPost = function (transCode,reqBody,success,error) {

    /*$.ajax({
     type:'POST',
     url:transCode,
     data: reqBody,
     dataType: 'json',
     success:function(res){
     success(res);
     },
     error:function(res){
     error(res);
     }
     });*/

    reqwest({
        url: transCode,
        method: 'post',
        type: 'json',
        data: reqBody,
        success: function (res) {
            success(res);
        },
        error:function(err){

        }
    })

}

const fetchGet = function (transCode,reqBody,success,error) {

    /*$.ajax({
     type:'GET',
     url:transCode,
     dataType: 'json',
     success:function(res){
     success(res);
     },
     error:function(res){
     error(res);
     }
     });*/

    reqwest({
        url: transCode,
        method: 'get',
        type: 'json',
        data:reqBody,
        success: function (res) {
            success(res);
        },
        error:function(err){

        }
    })

}


const getFieldArray = function (objectList, name) {

    var data = [];
    objectList.forEach(function (record,item) {
        data.push(record[name]);
    });
    return data;

}


exports.fetchPost = fetchPost;
exports.fetchGet = fetchGet;
exports.getFieldArray = getFieldArray;









